package com.hongkzh.www.look.enterprise.userinfo.presenter;

import android.util.Log;

import com.hongkzh.www.look.model.bean.AttenedBean;
import com.hongkzh.www.look.enterprise.userinfo.model.bean.MediaCompData;
import com.hongkzh.www.other.api.UrlWrapper;
import com.hongkzh.www.other.okhttp.CallBackUtil;
import com.hongkzh.www.other.okhttp.OkhttpUtil;
import com.hongkzh.www.look.enterprise.userinfo.view.iview.MediaBaseInfoIView;
import com.hongkzh.www.presenter.BasePresenter;

import okhttp3.Call;

import static com.hongkzh.www.other.api.Api.FOLLOWADD;
import static com.hongkzh.www.other.api.Api.FOLLOWDELETE;
import static com.hongkzh.www.other.api.Api.GETUSERInfo;

/**
 * Created by as on 2018/3/31.
 * 媒体简介
 */

public class MediaComPresenter extends BasePresenter<MediaBaseInfoIView> {


    @Override
    public void attachView(MediaBaseInfoIView iView) {
        super.attachView(iView);
    }

    // 请求企业信息的接口
    public void GetMediaComInfo(String loginUid, String comId) {

        String url = GETUSERInfo(loginUid, comId);


        OkhttpUtil.okHttpPost(url, new CallBackUtil<MediaCompData>() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(MediaCompData response) {
                getIView().onShowMediaComInfo(response);
            }

        });
    }


    // 添加关注
    public void GetFollowAdd(String loginUid, String followUserId) {

        UrlWrapper urlWrapper = UrlWrapper.getInstance();
        urlWrapper.addParameter("loginUid", loginUid);
        urlWrapper.addParameter("followUserId", followUserId);
        String url = FOLLOWADD + urlWrapper.getRequestURL();
        Log.i("添加关注的url===", url);

        OkhttpUtil.okHttpPost(url, new CallBackUtil<AttenedBean>() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(AttenedBean response) {
                getIView().onShowIfAttend(response);
            }
        });
    }

    // 取消关注
    public void GetFollowDelete(String loginUid, String followUserId) {

        UrlWrapper urlWrapper = UrlWrapper.getInstance();
        urlWrapper.addParameter("loginUid", loginUid);
        urlWrapper.addParameter("followUserId", followUserId);
        String url = FOLLOWDELETE + urlWrapper.getRequestURL();
        Log.i("添加关注的url===", url);

        OkhttpUtil.okHttpPost(url, new CallBackUtil<AttenedBean>() {
            @Override
            public void onFailure(Call call, Exception e) {

            }

            @Override
            public void onResponse(AttenedBean response) {
                getIView().onShowNoAttend(response);
            }
        });
    }


    @Override
    public MediaBaseInfoIView getIView() {
        return super.getIView();
    }

    @Override
    public void detachView() {
        super.detachView();
    }
}
